/**
 * Inspired by ControllerFactory.java in Workshop 4.
 * Makes sure every controller is a singleton. 
 */

package alpaca.ctrl;

import java.util.HashMap;
import java.util.Map;

/**
 * The ControllerFactory holds all the controllers in
 * a static map which makes it possible to get the and 
 * execute them from anywhere.
 *
 */
public class ControllerFactory {

	private final static Map<Class<? extends IController>, IController> ctrls = 
							new HashMap<Class<? extends IController>, IController>();
	
	static {
		ctrls.put(StartCtrl.class, new StartCtrl());
		ctrls.put(StopCtrl.class, new StopCtrl());
		ctrls.put(AddUserCtrl.class, new AddUserCtrl());
		ctrls.put(RemoveUserCtrl.class, new RemoveUserCtrl());
		ctrls.put(EditUserCtrl.class, new EditUserCtrl());
		ctrls.put(SearchLogCtrl.class, new SearchLogCtrl());
	}

	public static IController getController(Class<? extends IController> ctrl) {
		return ctrls.get(ctrl);
	}
	
}
